package com.cskaoyan;


import java.sql.*;

/**
 * 创建日期: 2022/08/25 11:41
 *
 * @author ciggar
 */
public class SecondJDBC {

    public static void main(String[] args) throws SQLException {

        // 1. 注册驱动
//        DriverManager.registerDriver(new Driver());

        // 2. 建立连接
        Connection connection = DriverManager.getConnection(FirstJDBC.url, FirstJDBC.username, FirstJDBC.password);

        // 3. 获取statement对象
        Statement statement = connection.createStatement();

        // 4. 发送SQL语句
        ResultSet resultSet = statement.executeQuery("select * from city");

        // 5. 解析结果集
        while (resultSet.next()) {
            // 获取对应的列的数据
            int id = resultSet.getInt(1);
            String name = resultSet.getString(2);
            int pId = resultSet.getInt(3);

            System.out.println("id:" + id + ",name:" + name + ",pId:" + pId);
        }

        // 6. 关闭资源
        resultSet.close();
        statement.close();
        connection.close();
    }
}
